package com.mazaiting.classfile.constant.info;

import com.mazaiting.classfile.ClassReader;
import com.mazaiting.classfile.constant.ConstantPool;

/**
 * 表示java.lang.String字面量
 *
 * @author mazaiting
 * @since 2021/8/11
 */
public class ConstantStringInfo extends ConstantInfo {
    /**
     * 字符串常量池索引 无符号 u2
     */
    private int stringIndex;

    public ConstantStringInfo(ConstantPool pool) {
        super(pool);
    }

    @Override
    public void readInfo(ClassReader reader) {
        this.stringIndex = reader.readU2ToUnsignedShort();
    }

    /**
     * 获取字符串
     * @return 字符串
     */
    public String getString() {
        return this.pool.getUtf8(this.stringIndex);
    }

    @Override
    public String toString() {
        return "ConstantStringInfo{" +
                "stringIndex=" + stringIndex +
                '}';
    }
}


















